package com.cxx.purchasecharge.dal.impl;

import javax.persistence.Query;

import org.apache.commons.collections.CollectionUtils;

import com.cxx.purchasecharge.core.model.persistence.GoodsDepository;
import com.cxx.purchasecharge.dal.GoodsDepositoryDao;
import com.cxx.purchasecharge.dal.common.MyGenericDaoImpl;

public class GoodsDepositoryDaoImpl extends MyGenericDaoImpl<GoodsDepository, Long> implements GoodsDepositoryDao {

	public GoodsDepositoryDaoImpl() {
		super(GoodsDepository.class);
	}

	@Override
	public GoodsDepository findByName(String name) {
		String sql = "select gd from GoodsDepository gd where gd.name = ?1";
		Query query = getEntityManager ().createQuery (sql, GoodsDepository.class);
		query.setParameter (1, name);
		return CollectionUtils.isNotEmpty (query.getResultList ()) ? (GoodsDepository)query.getResultList ().get (0) : null;
	}

}
